<?php
/**
 * Chinese Text Conversion
 *
 * http://www.phpclasses.org/browse/package/1406/
 * 
 * $Id: ctc.php 9 2009-04-26 06:35:12Z bole.Chen $
 **/

require_once ROOT.'includes'.DS.'classes'.DS.'CTC'.DS.'class.Chinese.php';

class ctc extends Chinese {
    
    var $loaded = false;

    function ctc($str="", $from='UTF8', $to='PinYin') {

        $this->codetable_dir = ROOT.'includes'.DS.'classes'.DS.'CTC'.DS.'tables'.DS;

		$this->config['SourceLang'] = $from;
        $this->config['TargetLang'] = $to;
	    $this->SourceText = $str;

        if ($from=='UTF8' && $to=='PinYin') {
            $this->config['SourceLang'] = $from = 'GB2312';
            $this->SourceText = iconv('UTF-8', 'GB2312', $this->SourceText);
        }

        if ($this->loaded == false) {
    		$this->OpenTable();
            $this->loaded = true;
        }
    }

    function ConvertIT($str=null) {
        if ($str) $this->ctc($str, $this->config['SourceLang'], $this->config['TargetLang']);
        $result = parent::ConvertIT();
        return str_replace(' ', '', $result);
    }
}
?>
